package com.lanou3g.mynewstest.module.news.comic;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou3g.mynewstest.R;
import com.lanou3g.mynewstest.beans.ComicBeans;
import com.lanou3g.mynewstest.tools.MyRequestQueue;

/**
 * Created by dllo on 16/1/26.
 */
public class ComicGridViewAdapter extends BaseAdapter {
    private Context context;
    private ComicBeans data;

    public ComicGridViewAdapter(Context context, ComicBeans data) {
        this.context = context;
        this.data = data;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyComicViewHolder holder;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_comic,parent,false);
            holder=new MyComicViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder= (MyComicViewHolder) convertView.getTag();
        }
        holder.title.setText(data.getT1444270454635().get(position).getTitle());
        MyRequestQueue.setNetImage(holder.imageView, data.getT1444270454635().get(position).getImgsrc());
        return convertView; // 返回ImageView
    }



    @Override
    public long getItemId(int position) {

        return position;
    }


    @Override
    public Object getItem(int position) {
        return null!=data.getT1444270454635()?data.getT1444270454635().get(position):null;
    }


    @Override
    public int getCount() {
        return null!=data.getT1444270454635()?data.getT1444270454635().size():0;
    }
    public void addBeans(ComicBeans beans) {
        this.data=beans;
        notifyDataSetChanged();
    }
    class MyComicViewHolder extends RecyclerView.ViewHolder {
        private NetworkImageView imageView;
        private TextView title;

        public MyComicViewHolder(View itemView) {
            super(itemView);
            imageView= (NetworkImageView) itemView.findViewById(R.id.item_comic_net);
            title= (TextView) itemView.findViewById(R.id.item_comic_title_tv);
        }
    }
}